﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CmpEdu
{
    public partial class FrmT10_2Login : Form
    {
        public FrmT10_2Login()
        {
            InitializeComponent();
        }

        public static string UserLevel;                 //用来捕获登录界面后返回的用户等级
        private void FrmT10_2_Load(object sender, EventArgs e)
        {
            this.Text = "用户登录";
            TbName.Text = "admin";
            TbPwd.Text = "bushuang09";
        }

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            if (TbName.Text == "" || TbPwd.Text == "")
            {
                MessageBox.Show("用户名或密码不能为空！", "出错",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string uname = TbName.Text.Trim();
            string upwd = TbPwd.Text.Trim();

            //用户是否合法
            string IsOk = UserManager.CheckUser(uname, upwd);
            if (IsOk=="3")
            {
                MessageBox.Show("用户名或密码错误！", "出错",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                UserLevel = IsOk;                       //登录成功，跳转到不同的用户界面，很重要，后面要用
                this.Hide();
                Frm10_2Main main = new Frm10_2Main();   //新建一个form，并且让其出现
                main.Show();
            }
        }

        /// <summary>
        /// 注册新用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LbRegister_Click(object sender, EventArgs e)
        {
            this.Hide();
            Frm10_2Reg reg = new Frm10_2Reg();
            reg.Show();
        }
    }
}
